﻿using System;
using System.Collections.Generic;
using Microsoft.Phone.Controls;
using PhoneCore.Framework;
using PhoneCore.Framework.Configuration;
using PhoneCore.Framework.Diagnostic.Tracing;
using PhoneCore.Framework.IoC;
using PhoneCore.Framework.Views.Command;
using SecureBox.UI.Infrastructure;

namespace SecureBox.UI.ViewModel
{
    public class HealthViewPageModel : ViewModelBase
    {
        [Dependency]
        public ITrace Trace { get; set; }

        [Dependency("Health")]
        public ITraceCategory Category { get; set; }

        public HealthViewPageModel()
        {
            EraseCommand = new ExecuteCommand(OnEraseCommand);
            SendCommand = new ExecuteCommand(OnSendCommand);
        }

        private void OnSendCommand()
        {
            Trace.Warn(Category, "send command");
            throw new NotImplementedException();
        }

        private void OnEraseCommand()
        {
            Trace.Warn(Category, "erase command");
            DefaultTraceController controller = new DefaultTraceController(TraceFactory.GetTrace() as DefaultTrace, "Resources/Templates/DefaultTraceReport.txt");
            controller.Cleanup();
            //update browser content
            NavigationService.NavigateTo("Health",
                        new Dictionary<string, object>() { { "Health.Trace", TraceName } });
        }

        public string Content { get; set; }
        private string TraceName { get; set; }

        /// <summary>
        /// Command for erase button click
        /// </summary>
        public ExecuteCommand EraseCommand
        {
            get;
            private set;
        }

        /// <summary>
        /// Command for send button click
        /// </summary>
        public ExecuteCommand SendCommand
        {
            get;
            private set;
        }


        protected override void ReadNavigationParameters()
        {
            TraceName = (string) NavigationParameters["Health.Trace"];
            Trace.Info(Category, TraceName);
            DefaultTraceController controller = new DefaultTraceController(TraceFactory.GetTrace() as DefaultTrace, "Resources/Templates/DefaultTraceReport.txt");
            var writer = controller.GenerateReport();
            Content = writer.ToString();
            //RaisePropertyChanged("Content");
        }
    }
}
